#!/usr/bin/python3
# -*- coding: UTF-8 -*-


class Solution(object):
    def lengthOfLongestSubstring(self, s):
        """
        :type s: str
        :rtype: int
        """
        left = 0
        right = 0
        max_length = 0
        char_set = set()
        while right < len(s):
            if s[right] in char_set:
                char_set.remove(s[left])
                left += 1
            char_set.add(s[right])
            max_length = max(max_length, right - left + 1)
            right += 1
        return max_length
    
if __name__ == '__main__':
    solution = Solution()
    print(solution.lengthOfLongestSubstring("abcabcbb"))
    print(solution.lengthOfLongestSubstring("bbbbb"))
    print(solution.lengthOfLongestSubstring("pwwkew"))
    print(solution.lengthOfLongestSubstring(" "))
    print(solution.lengthOfLongestSubstring("a"))
    print(solution.lengthOfLongestSubstring("bcdbcdaeb"))